package gzhaoku.com.machinemain.jssdk.commands;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

import gzhaoku.com.machinemain.BuildConfig;

public class MachineInfoCommand extends BaseCommand{


    public MachineInfoCommand(Activity context) {
        super(context);
    }

    @Override
    public boolean isAccept(String command) {
        if(StringUtils.startsWithIgnoreCase(command, "hk_getInfo")){
            return true;
        }
        return false;
    }

    @Override
    public CommandResult execute() {
        CommandResult r = new CommandResult();
        Map<String, Object> p = new HashMap();
        try {
            p.put("VersionCode", context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode);
            p.put("VersionName", context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        r.data = p;

        return r;
    }
}
